package com.elepro.shoppingmall.controller;

import com.elepro.shoppingmall.entity.Goods;
import com.elepro.shoppingmall.entity.GoodsType;
import com.elepro.shoppingmall.service.goods.GoodsServiceIm;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
public class GoodsController {
    @Resource
    private GoodsServiceIm goodsService;

    @GetMapping("/loadAllGoods")
    public List<Goods> loadAllGoods() {
        return goodsService.sLoadAllGoods();
    }

    @GetMapping("/countAllGoods")
    public Long countAllGoods() {
        return goodsService.countAllGoods();
    }

    @GetMapping("/pageLoadAllGoods")
    public List<Goods> pageLoadAllGoods(@RequestParam(defaultValue = "1") int pageNumber, int size) {
        return goodsService.pageGoodsList(pageNumber, size).getList();
    }

    @GetMapping("/loadAllGoodsType")
    public List<GoodsType> loadAllGoodsType() {
        return goodsService.sLoadAllGoodsType();
    }

    @GetMapping("/loadGoodsById")
    public List<Goods> loadGoodsById(long id) {
        return goodsService.sLoadGoodsById(id);
    }

    @GetMapping("/findGoodsBySearch")
    public List<Goods> findGoodsBySearch(String goodsName) {
        return goodsService.sFindGoodsBySearch(goodsName);
    }

}
